package com.alibaba.service;

import com.alibaba.bean.PostNote;
import com.alibaba.bean.PostResult;
import com.alibaba.mapper.PostMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PostService {

    @Autowired
    private PostMapper postMapper;

    public PostResult send(PostNote postNote) {
        PostResult pr = new PostResult();
        PostNote pn = new PostNote();
        pr.setResult(false);
        pr.setData(null);
        try{
            postMapper.saveNote(postNote);
            if (postMapper.checkSave(postNote.getUserId()) != null) {
                pr.setErrorMsg("发帖成功");
                pr.setResult(true);
            } else {
                pr.setErrorMsg("发帖失败");
            }
        } catch (Exception e) {
            pr.setErrorMsg(e.getMessage());
            e.printStackTrace();
        }
        return pr;
    }

}
